package com.jl15988.chainlog.callback;

import com.jl15988.chainlog.model.ChainApiLog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 接口监控回调接口
 */
public interface ChainApiCallback {

    /**
     * 完成后的回调处理
     *
     * @param chainApiLog 接口链信息
     * @param request     HTTP请求对象
     * @param response    HTTP响应对象
     */
    void onChainComplete(ChainApiLog chainApiLog, HttpServletRequest request, HttpServletResponse response);

    /**
     * 异常时的回调处理
     *
     * @param chainApiLog 接口链信息
     * @param request     HTTP请求对象
     * @param response    HTTP响应对象
     * @param exception   异常信息
     */
    default void onChainException(ChainApiLog chainApiLog, HttpServletRequest request,
                                  HttpServletResponse response, Throwable exception) {
        // 默认实现为空，子类可选择性重写
    }
}